// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.Styles;

import java.io.Serializable;

public class ShortList implements Serializable {
    private static final long serialVersionUID = 1L;
    private short[] value;
    private short count = 0;
    private final boolean fastExpand;

    public ShortList() {
        this(0);
    }

    public ShortList(int size) {
        this(true, size);
    }

    public ShortList(boolean _fastExpand, int size) {
        this.fastExpand = _fastExpand;
        this.value = new short[size];
    }

    public short add(short f) {
        if (this.count == this.value.length) {
            short[] _short = this.value;
            if (this.fastExpand) {
                this.value = new short[(_short.length << 1) + 1];
            } else {
                this.value = new short[_short.length + 1];
            }

            System.arraycopy(_short, 0, this.value, 0, _short.length);
        }

        this.value[this.count] = f;
        return this.count++;
    }

    public short remove(int idx) {
        if (idx < this.count && idx >= 0) {
            short _short = this.value[idx];
            if (idx < this.count - 1) {
                System.arraycopy(this.value, idx + 1, this.value, idx, this.count - idx - 1);
            }

            this.count--;
            return _short;
        } else {
            throw new IndexOutOfBoundsException("Referenced " + idx + ", size=" + this.count);
        }
    }

    public void addAll(short[] _short) {
        this.ensureCapacity(this.count + _short.length);
        System.arraycopy(_short, 0, this.value, this.count, _short.length);
        this.count = (short)(this.count + _short.length);
    }

    public void addAll(ShortList f) {
        this.ensureCapacity(this.count + f.count);
        System.arraycopy(f.value, 0, this.value, this.count, f.count);
        this.count = (short)(this.count + f.count);
    }

    public short[] array() {
        return this.value;
    }

    public int capacity() {
        return this.value.length;
    }

    public void clear() {
        this.count = 0;
    }

    public void ensureCapacity(int size) {
        if (this.value.length < size) {
            short[] _short = this.value;
            this.value = new short[size];
            System.arraycopy(_short, 0, this.value, 0, _short.length);
        }
    }

    public short get(int index) {
        return this.value[index];
    }

    public boolean isEmpty() {
        return this.count == 0;
    }

    public int size() {
        return this.count;
    }

    public short[] toArray(short[] _short) {
        if (_short == null) {
            _short = new short[this.count];
        }

        System.arraycopy(this.value, 0, _short, 0, this.count);
        return _short;
    }

    public void trimToSize() {
        if (this.count != this.value.length) {
            short[] _short = this.value;
            this.value = new short[this.count];
            System.arraycopy(_short, 0, this.value, 0, this.count);
        }
    }
}
